// /////////////////////////////////////////////////////////////////////////////
// r3 group ////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////
$.fn.getR3data = function(_lotto_id,_gametype){
 var subid = $("div#rdiSubid input:radio:checked").val();
 $().disAreaObj();
 $.getJSON('op.php?op=xml_3d&fp=rate_3d&playtype=r3&lotto_id_3d='+_lotto_id+"&gametype="+_gametype+"&disk="+ $("select#slcDisk").val()+ "&subid=" + subid ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
        var disk = $("select#slcDisk").val();
        var subid = $("div#rdiSubid input:radio:checked").val();
        switch(subid){
          case '2': $().creatRateData(ratedata.r20_2,_gametype,disk, subid); break;
          case '1': $().creatRateData(ratedata.r20_1,_gametype,disk, subid); break;
          case '0': $().creatRateData(ratedata.r20_0,_gametype,disk, subid); break;
        }
        
        $("div#errormsg").text("");
        $("div#mainPageData").show();
      }
      $().redisAreaObj();
  });
};


// create table data
$.fn.creatRateData = function(rdata,_gametype,disk, subid){
    dataLen = rdata.number.length;
    urlPre = "op.php?op=member_3d&fp=bet_fast&palygroup=r3&bettype=20&gametype="+_gametype+"&disk="+disk+"&subid="+ subid;
    $("tbody#tbdr20").empty();
    var rnum = 20;
    var tempTr = 5; // cols of each rows
    var classType = "";
    for(i = 0; i < dataLen; i++){
        classType = rdata.number[i].substr(0,1);    
        hrefStr = urlPre + "&num=" + rdata.number[i] + "&rate=" + rdata.rates[i];
        if(i == 0){
            $('<tr class="td2" align=center><th class="bg'+classType+'">'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td></tr>').appendTo("tbody#tbdr20");
        }else if(i > 0 && i % tempTr == 0){
          $('<tr class="td2" align=center><th class="bg'+classType+'">'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td></tr>').appendTo("tbody#tbdr20");
        }else{
          $('<th class="bg'+classType+'" align=center>'+rdata.number[i]+'</th><td class="betnum"><a href="'+hrefStr+'" class="betRateNum" target="leftFrame">'+rdata.rates[i]+'</a></td><td><input type="text" size="3" name="r'+rnum+'_'+rdata.number[i]+'" /></td>').appendTo("tbody#tbdr20 tr:last");
        }
    }
    // change text or checkbox type
    var timebtnType = $("input:hidden#timebtnType").val();
    if(timebtnType == "checkbox"){
      $().timebtnTypeToCheckbox(); 
    }
};

// set 0-9 numbers
$.fn.getNum3 = function(num){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var tmp3 = "";
   return $(this).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      tmp3 = tmpName.substr(6,1);
      if(tmp1 == num || tmp2 == num || tmp3 == num){
        return true;
      }else{
        return false;
      }
   });
};

// set 3 pair numbers
$.fn.getPairNum3 = function(){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var tmp3 = "";
   return $(this).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      tmp3 = tmpName.substr(6,1);
      if(tmp1 == tmp2 && tmp1 ==tmp3 && tmp2 == tmp3){
        return true;
      }else{
        return false;
      }
   });
};

// set 2 pair numbers
$.fn.getPairNum2 = function(){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var tmp3 = "";
   return $(this).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      tmp3 = tmpName.substr(6,1);
      if(tmp1 == tmp2 || tmp1 ==tmp3 || tmp2 == tmp3){
        return true;
      }else{
        return false;
      }
   });
};

$.fn.addThreeNum = function(chkStr){
  var reVal =  chkStr.substr(0,1) - 0;
  reVal += chkStr.substr(1,1) - 0;
  reVal += chkStr.substr(2,1) - 0;
  return reVal;
};

// set comment numbers
$.fn.getPairNum4 = function(){
   var tmpName = "";
   var tmp1 = "";
   var tmp2 = "";
   var tmp3 = "";
   return $(this).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,1);
      tmp2 = tmpName.substr(5,1);
      tmp3 = tmpName.substr(6,1);
      if(tmp1 == tmp2 || tmp1 == tmp3 || tmp2 == tmp3){
        return false;
      }else{
        return true;
      }
   });
};


// set 2 pair numbers
$.fn.getPairByArr = function(oArr){
   var tmpName = "";
   var tmp1 = "";
   var strTemp = "," + oArr.join(",") + ",";
   return $(this).filter(function(){
      tmpName = $(this).attr("name");
      tmp1 = tmpName.substr(4,3);
      if(strTemp.indexOf(tmp1) > 0){
        return true;
      }else{
        return false;
      }
   });
};